
#include <iostream>
using std::cout;
using std::endl;
using std::string;

#include <SimpleAmqpClient/SimpleAmqpClient.h>

struct AmqpInfo
{
    string amqpUrl = "amqp://guest:guest@localhost:5672";
    string exchangor = "mytest";
    string amqpQueue = "queue1";
    string routingKey = "key1";
};

void testPublisher()
{
    using namespace AmqpClient;
    AmqpInfo amqpinfo;
    Channel::ptr_t channel = Channel::Create();
    BasicMessage::ptr_t message = BasicMessage::Create("hello, mykey1");
    channel->BasicPublish(amqpinfo.exchangor, amqpinfo.routingKey, message);
    pause();
}

void testConsumer()
{
    using namespace AmqpClient;
    AmqpInfo amqpinfo;
    Channel::ptr_t channel = Channel::Create();
    //指定从哪个队列中获取数据
    channel->BasicConsume(amqpinfo.amqpQueue);

    //定义一个信封
    Envelope::ptr_t envelope;
    bool ret = channel->BasicConsumeMessage(envelope, 3000);
    if(ret) {
        string msg = envelope->Message()->Body();
        cout << "receive msg:" << msg << endl;
    } else {
        cout << "get message timeout" << endl;
    }
}


int main()
{
    /* testPublisher(); */
    testConsumer();
    return 0;
}

